var http = require("/pages/utils/http.js")
const token = "TOKEN"
App({
  onLaunch: function () {
    var time = tt.getStorageSync("time")
    var curTime = new Date().getTime()
    var dateSpan=curTime-parseInt(time)
    var timeNum = Math.floor(dateSpan / (24 * 3600 * 1000));
    var accessToken = tt.getStorageSync(token)
    if (timeNum > 28 || (accessToken == "" ||
      accessToken == null || accessToken == undefined)) {
      this.GetBaiduAccessToken() 
    } 
  },
  func: {
    reqLoading: http.reqCommon,
    req: http.reqNoLoading,
  },
  //获取百度的token
  GetBaiduAccessToken: function (cb) {
    var that = this
    this.func.req("https://aip.baidubce.com/oauth/2.0/token", {
      grant_type: "client_credentials",
      client_id: "",
      client_secret: ""
    }, function (res) {
      console.log("AAAAAAAa" + res)
      if (res.access_token) {
        tt.setStorageSync(token, res.access_token);
        tt.setStorageSync("time", new Date().getTime())
        cb(res.access_token)
      } else { 

      }
    })
  },
  showToastMsg: function (msg) {
    tt.showToast({
      title: msg,
      icon: "none"
    });
  }
})
